<template>
    <div class="userData">
        <el-row class="h100">
            <el-col :span="12" class="h50" v-for="item in state.data" :key="item.name">
                <div class="cont">
                    <div class="name">
                        {{ item.name }}
                    </div>
                    <div class="value">
                        <CountTo :startVal="0" :duration="1500" :endVal="item.value"></CountTo>
                        <span class="unit">{{ item.unit }}</span>
                    </div>
                </div>
            </el-col>
            <el-col :span="12" class="h50"></el-col>
            <el-col :span="12" class="h50"></el-col>
            <el-col :span="12" class="h50"></el-col>
        </el-row>
        <div class="line1"></div>
        <div class="line2"></div>
    </div>
</template>
<script setup>
import { reactive } from 'vue';
import { CountTo } from 'vue3-count-to'


const state = reactive({
    data: [
        { name: '总用户', value: 5000, unit: '人' },
        { name: '月用户', value: 5000, unit: '人' },
        { name: '会员比例', value: 75, unit: '%' },
        { name: '月会员比例', value: 25, unit: '%' },
    ]
})
const getData = () => {
    state.data = [
        { name: '总用户', value: 5000, unit: '人' },
        { name: '月用户', value: 5000, unit: '人' },
        { name: '会员比例', value: 75, unit: '%' },
        { name: '月会员比例', value: 25, unit: '%' },
    ]
    return
    // 以上是模拟数据，真是数据通过接口传入，如下
    request({
        url: 'analysisJudgment/getCategorize',
        method: 'post',
        data: {
        }
    }).then(res => {
        state.data = res;
        if (chatDistance) {
            setData()
        }
    })
}
</script>
<style lang="scss" scoped>
.userData {
    height: calc(100% - 52px);
    position: relative;
    padding: 20px;
    box-sizing: border-box;

    .cont {
        padding: 10px 10px 20px 30px;

        .name {
            font-size: 14px;
            color: rgba(255, 255, 255, 1);
            margin-top: 15px;
        }

        .value {
            font-size: 28px;
            font-weight: 600;
            color: rgba(55, 255, 206, 1);
            white-space: nowrap;

            .unit {
                font-size: 15px;
                font-weight: 500;
            }
        }
    }

    .h100 {
        height: 100%;
    }

    .h50 {
        height: 50%;
    }

    [class*=line] {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
    }

    $s: 2px;

    .line1 {
        height: $s;
        width: calc(100% - 40px);
        background: linear-gradient(90deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.5) 50%, rgba(255, 255, 255, 0) 100%);
    }

    .line2 {
        width: $s;
        height: calc(100% - 40px);
        background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.5) 50%, rgba(255, 255, 255, 0) 100%);
    }
}
</style>